$(function () {
  var app = {
    openId: GetRequest().openId,
    hostSever: getServerHost(),
    friend: '/api/longtaitou/friend',
    getFriendUrl: '/api/longtaitou/getFriendUrl',
    init: function () {
      // 判断是否关注
      // 请求微信姓名和url
      this.getCode();
    },
    getCode: function () {
      $.ajax({
        type: 'get',
        url: app.hostSever + app.getFriendUrl,
        // url: './json/test.json',
        data: {
          openId: app.openId
        }
      }).done(function (rp) {
        if (200 != rp.code) {
          alert(rp.msg);
          return;
        }
        $('.loading').hide();
        // $('.loading').hide();
        // $('.name').text(rp.res.nickname);
        $('#qrcode').qrcode({
          render: "canvas",
          foreground: "#000",
          background: "#FFF",
          typeNumber: -1, //计算模式
          correctLevel: 2, //二维码纠错级别
          width: 239, //宽度
          height: 239, //高度
          text: rp.res.friendUrl //任意内容
        });
        $('#qrcode canvas').css({
          'width': '2.39rem',
          'height': '2.39rem'
        });


        loadgo();


        function loadgo() {
          //判断手机是ios还是安卓
          if (1 === judgePhone().val) {
            console.log('html2canvas');
            html2canvas(document.querySelector("#container")).then(function (canvas) {
              var image = canvas.toDataURL("image/jpeg");
              $('.loading').show();
              $('body>img').show().attr('src', image);
              $('.loading').hide();
            });
          } else if (0 === judgePhone().val) {
            //判断是安卓手机使用
            console.log('domtoimage');
            domtoimage
              .toPng(document.querySelector("#container"))
              .then(function (dataUrl) {
                $('.loading').show();
                $('body>img').show().attr('src', dataUrl);
                $('.loading').hide();
              })
              .catch(function (error) {
                console.error('oops, something went wrong!', error);
              });
          }
        }
      })

    }
  };
  window.onload = function () {
    preventMove();
    app.init();
  }
})